import { Api } from '../api'

export interface LoginParams {
  username: string
  password: string
  captchaId: string
  captcha: string
  type?: 'account'
}

export interface LoginMobileParams {
  mobile: string
  code: string
  type: 'mobile'
}

export interface CaptchaModel {
  value: any
  captchaId: string
  imageData: string
}

export function loginApi(type: string, params: FormData) {
  let url = Api.PasswordLoginApi
  if (type === 'mobile')
    url = Api.PhoneLoginApi
  return usePost<string, FormData>(url, params, {
    // 设置为false的时候不会携带token
    token: false,
    // 开发模式下使用自定义的接口
    customDev: true,
    // 是否开启全局请求loading
    loading: true,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  })
}

export function loginByThird(params: FormData) {
  return usePost<string, FormData>(Api.ThirdQrLoginApi, params, {
    // 设置为false的时候不会携带token
    token: false,
    // 开发模式下使用自定义的接口
    customDev: true,
    // 是否开启全局请求loading
    loading: true,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  })
}

export function logoutApi() {
  return useGet(Api.LogoutApi)
}
